/**
 * 
 */
package com.xb.cloud.common.model.tree;

import java.util.List;

/**
 * 返回BO封装 树形结构节点
 * 
 * @author kexue
 *
 */
public class TreeNode<T> implements Comparable<TreeNode<T>> {
	// id
	private Long id;

	// 父节点id ==0为顶级节点
	private Long parentId;
	// 名称
	private String name;
	// 编码
	private String code;
	// 是否是叶子节点
	private byte isLeaf;
	// 排序
	private int sort;
	
	//层编号: 1 (非必须字段)
	private int layerNo;
	
	//层级串: 0/1/ (非必须字段)
	private String layers;
	

	//数据
	private T data;

	//子节点数组
	private List<TreeNode<T>> children;

	public TreeNode(){};
	/**
	 * @param id
	 * @param parentId
	 * @param name
	 * @param code
	 * @param isLeaf
	 * @param level
	 * @param sort
	 * @param data
	 */
	public TreeNode(Long id, Long parentId, String name, String code, byte isLeaf, Integer level, int sort,
			T data) {
		super();
		this.id = id;
		this.parentId = parentId;
		this.name = name;
		this.code = code;
		this.isLeaf = isLeaf;
		this.sort = sort;
		this.data = data;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	

	public byte getIsLeaf() {
		return isLeaf;
	}
	public void setIsLeaf(byte isLeaf) {
		this.isLeaf = isLeaf;
	}
	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public List<TreeNode<T>> getChildren() {
		return children;
	}

	public void setChildren(List<TreeNode<T>> children) {
		this.children = children;
	}


	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	public int getLayerNo() {
		return layerNo;
	}
	public void setLayerNo(int layerNo) {
		this.layerNo = layerNo;
	}
	 
	
	public String getLayers() {
		return layers;
	}
	public void setLayers(String layers) {
		this.layers = layers;
	}
	//排序规则： sort字段
	@Override
	public int compareTo(TreeNode<T> o) {
		if (o == null) {
			return 1;
		}

		return this.getSort() - o.getSort();
	}
	@Override
	public String toString() {
		return "TreeNode [id=" + id + ", parentId=" + parentId + ", name=" + name + ", isLeaf=" + isLeaf + ", sort="
				+ sort + "]";
	}

	
}
